package com.tianyadu.order;

import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.cloud.client.SpringCloudApplication;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;


/**
  * @Description: 订单服务启动主类
    @EnableDiscoveryClient ： 该注解将当前应用注册为springCloud应用中的客户端
 	@EnableFeignClients ： 该注解将当前服务注册为springCloud应用中的FeignClients客户端
	SpringCloudApplication：是@SpringBootApplication注解 @EnableDiscoveryClient注解 @EnableCircuitBreaker注解集合
	EnableHystrixDashboard： 开启Hystrix熔断可视化界面
	 * @date:   2018/11/21 16:35
  */
@EnableFeignClients(basePackages = {"com.tianyadu.product.client"})
@SpringCloudApplication
@ComponentScan(basePackages = "com.tianyadu")
@EnableHystrixDashboard
public class OrderApplication {

	public static void main(String[] args) {
		SpringApplication.run(OrderApplication.class, args);
	}

	@Bean
	public ServletRegistrationBean getServlet() {
		HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
		ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet);
		registrationBean.setLoadOnStartup(1);
		registrationBean.addUrlMappings("/hystrix.stream");
		registrationBean.setName("HystrixMetricsStreamServlet");
		return registrationBean;
	}
}
